<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            title="商家备注"
            :async="true"
            width="550px"
            @confirm="handleSubmit"
            @close="handleClose"
        >
            <el-form ref="formRef" :model="formData" :rules="rules">
                <el-form-item prop="order_remark">
                    <el-input
                            type="textarea"
                            v-model="formData.order_remark"
                            placeholder="请输入备注"
                            :rows="10"
                    ></el-input>
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import { orderRemark, orderdetail } from '@/api/order'
import Popup from '@/components/popup/index.vue'
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()

const rules = {
    order_remark: [
        {
            required: true,
            message: "请输入备注",
            trigger: ["blur", "change"],
        },
    ],
};

const formData = reactive({
    order_no: '',
    order_remark: ''
})

const open = () => {
    popupRef.value?.open()
}

const setFormData = (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
}

const getDetail = async (row: Record<string, any>) => {
    // const { id, order_remark } = await orderdetail({
    //     id: row.id
    // })
    // formData.id = id
    // formData.order_remark = order_remark
}

const handleClose = () => {
    emit('close')
}

//提交
const handleSubmit = async () => {
    await formRef.value?.validate();
    popupRef.value?.close()
    emit('success', formData)
}

defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
